package com.study.controller;

import com.study.domain.Account;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;

/**
 * 请求参数绑定
 */
@Controller
@RequestMapping("/param")
public class ParamController {

    /**
     * 请求参数绑定入门
     * @return
     */
    @RequestMapping("/testParam")
    public String testParam(String username){
        System.out.println("执行了");
        System.out.println(username);
        return "success";
    }

    @RequestMapping("/saveAccount")
    public String saveAccount(Account account, HttpServletResponse response, @RequestBody String requestBody) throws Exception{
        System.out.println("执行了");
        System.out.println(account);
        response.setContentType("text/html;charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(account.getUsername());
        return null;
    }
}
